<template lang="">
  <div class="popu_container">
    {{isEditor}}
     <!-- 弹出层 -->
    <van-popup
      v-model="show"
      position="bottom"
      :style="popupStyle"
    >
    <div class="close" @click="popupClose"> X </div>
      <div class="header">
        <div class="search">
          <div class="myChannels">我的频道</div>
          <div class="editorChannels" @click="editorBtnClick">{{editorText }}</div>
        </div>
      </div>
      <div class="main">
        <van-grid :gutter="10">
          <van-grid-item
            v-for="(item,index) in navLists"
            :key="index"
            @click="navListsClick(index)"
          >
          <template #text>
            <div :class="isActive(index)" class="text">{{ item.name }}</div>
          </template>
          <template #icon>
            <van-icon name="cross" v-if="editorText === '完成'" />
          </template>
          </van-grid-item>
        </van-grid>
      </div>
      <footer>
        <div class="recommend">频道推荐</div>
        <van-grid :gutter="10">
          <van-grid-item
            :text="item.name"
            v-for="(item, index) in allChannels"
            :key="index"
            @click="recommendChannelClick(index)" >
            <template #icon>
              <van-icon name="plus" size="10px"/>
            </template>
          </van-grid-item>
        </van-grid>
      </footer>
    </van-popup>
  </div>
</template>

<script>

export default {
  props: ['show', 'popupStyle', 'navLists', 'allChannels', 'active'],
  data () {
    return {
      lineHeightIndex: '',
      isEditor: false,
      editorText: '编辑'
    }
  },
  created () {
    this.lineHeightIndex = this.active
  },
  methods: {
    popupClose () {
      this.$emit('vanPopupclose')
    },
    isActive (index) {
      if (index === this.lineHeightIndex) {
        return 'active'
      } else {
        return ''
      }
    },
    navListsClick (index) {
      if (this.isEditor) {
        if (this.lineHeightIndex > index) {
          this.lineHeightIndex--
        }
        this.$emit('edmitNavLists', index)
      } else {
        this.lineHeightIndex = index
        this.$emit('edmitNavlistsClass', index)
      }
    },
    editorBtnClick () {
      this.isEditor = !this.isEditor
      if (this.isEditor) {
        this.editorText = '完成'
      } else {
        this.editorText = '编辑'
      }
    },
    // 点击 推荐频道 向 我的频道中添加对应的标签
    recommendChannelClick (index) {
      if (this.isEditor) {
        // console.log(index)
        this.$emit('recommendChannelClick', index)
      }
    }
  },
  // 监听父组件的active
  watch: {
    active (newValue) {
      this.lineHeightIndex = newValue
    }
  }
}
</script>

<style lang="less" scoped>
.popu_container {
  .close {
    position: absolute;
    left: 25px;
    top: 25px;
    width: 15px;
    height: 15px;
    font-size: 45px;
    color: #ccc;
  }
  .search {
    display: flex;
    justify-content: space-between;
    font-size: 25px;
    margin: 100px 20px 30px;
    .myChannels {
      font-size: 30px;
    }
    .editorChannels {
      width: 120px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      color: #f85959;
      border: 1px solid #f85959;
      border-radius: 20px;
    }
  }
  .main {
    /deep/.van-grid-item__icon-wrapper {
      position: absolute;
      top: 0;
      right: 0;
      width: 24px;
      height: 24px;
      line-height: 24px;
      font-size: 10px;
      color: #fff;
      text-align: center;
      background-color: #cacaca;
      border-radius: 50%;
      transform: translate(50%, -50%);
    }
  }
  .main,
  footer {
    /deep/.van-grid-item__content {
      width: 160px;
      height: 90px;
      background-color: #f4f5f6;
      .active.van-grid-item__text {
        color: #f85959;
      }
    }
  }
  footer {
    font-size: 30px;
    .recommend {
      margin: 20px;
    }
    /deep/.van-grid-item__content {
      flex-direction: row;
    }
    /deep/.van-grid-item__icon-wrapper {
      margin-right: 10px;
    }
  }
  /deep/.active {
    color: #f85959;
  }
  /deep/.text {
    font-size: 25px;
  }
}
</style>
